package cn.ibizlab.codegen.groovy.support;


import com.google.common.base.CaseFormat;
import net.ibizsys.model.IPSModelObject;
import net.ibizsys.model.dataentity.service.IPSDEMethodDTO;
import org.springframework.util.StringUtils;

public class PSModelExtension {

    public static String getRealCodeName(IPSModelObject iPSModelObject) {
        String strCodeName = iPSModelObject.getCodeName();
        if (!StringUtils.hasLength(strCodeName)) {
            strCodeName = iPSModelObject.getName();
        }
        //判断是否有下划线
        if (strCodeName.indexOf("_") != -1) {
            strCodeName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, strCodeName.toLowerCase());
        } else {
            strCodeName = StringUtils.capitalize(strCodeName);
        }
        if (StringUtils.hasLength(strCodeName)) {
            if (iPSModelObject instanceof IPSDEMethodDTO) {
                if (strCodeName.endsWith("filterDto")) {
                    strCodeName = strCodeName.substring(0, strCodeName.length() - 9) + "FilterDTO";
                }
                if (strCodeName.endsWith("filterdto")) {
                    strCodeName = strCodeName.substring(0, strCodeName.length() - 9) + "FilterDTO";
                }
                if (strCodeName.endsWith("Dto")) {
                    strCodeName = strCodeName.substring(0, strCodeName.length() - 3) + "DTO";
                }
                if (strCodeName.endsWith("dto")) {
                    strCodeName = strCodeName.substring(0, strCodeName.length() - 3) + "DTO";
                }
            }
        }
        return strCodeName;
    }


}
